package com.example.myapplication.work

import android.content.Context
import android.util.Log
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters
import java.util.*

class SleepWork(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {

    override fun doWork(): Result {
        Log.e("WorkerFragment", "${Thread.currentThread().name} start dowork ${Date()}")
        try {
            Thread.sleep(1000 * 10)
        } catch (e: Exception) {
            return Result.failure(Data.Builder().apply {
                this.putString("name" , "wuyongzheng")
                this.putString("type" , "failure")
            }.build())
        } finally {
            Log.e("WorkerFragment", "${Thread.currentThread().name} end dowork ${Date()}")
        }
        return Result.success(Data.Builder().apply {
            this.putString("name" , "wuyongzheng")
            this.putString("type" , "success")
        }.build())
    }
}